package com.ogawa.base.base

import android.app.Application
import androidx.multidex.MultiDexApplication
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils
import com.ogawa.base.BuildConfig
import com.ogawa.base.mqtt.MqttManager
import com.ogawa.base.utils.AppException
import com.tencent.smtt.sdk.QbSdk
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure


open class BaseApp : MultiDexApplication() {

    companion object {
        lateinit var appContext: Application
//        private var activityList = Stack<Activity>()

//        fun addActivity(act: Activity) {
//            activityList.add(act)
//        }
//
//        fun removeActivity(act: Activity) {
//            activityList.remove(act)
//        }
//
//        fun getTopActivity(act: Activity): Activity {
//            return activityList.peek()
//        }
//
//        fun exitApp() {
//            for (act in activityList) {
//                if (act != null && !act.isFinishing) {
//                    act.finish()
//                }
//            }
//        }
    }

    override fun onCreate() {
        super.onCreate()
        appContext = this
        if (packageName != "com.ogawa.joypal") {
            initARouter()
        }
        AppException.getAppExceptionHandler(this)
        MqttManager.getInstance().initClient(this)
        registerActivityLifecycleCallbacks(ActivityLifecycle())
        initX5()
    }

    private fun initX5() {
        val cb: QbSdk.PreInitCallback = object : QbSdk.PreInitCallback {
            override fun onViewInitFinished(arg0: Boolean) {
                LogUtils.e("app", " onViewInitFinished is $arg0")
            }

            override fun onCoreInitFinished() {}
        }
        QbSdk.initX5Environment(this, cb)
    }

    protected fun initARouter() {
        if (BuildConfig.DEBUG) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        LogUtils.e("initARouter")
        ARouter.init(this)
    }





}